package Models;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

import dataobjects.Film;
import dataobjects.Vorstellung;

public class VorstellungDetailModel extends AbstractTableModel{
	private String[] spaltenNamen = {"Saal-Name", "Datum", "Film-Name", "Beginn", "Dauer"};
	ArrayList<Vorstellung> alleEintraege = new ArrayList<Vorstellung>();
    private boolean columnEditable;
    private int column;
	
	public Vorstellung getSelectedVorstellung(int i)
	{
		return alleEintraege.get(i);
	}
    public void arrayListEinfuegen(ArrayList<Vorstellung> arraylist)
    {
           alleEintraege = arraylist;
    }
    
    public void clearArrayList()
    {
           alleEintraege.clear();
    }

    public int getColumnCount() {
        return spaltenNamen.length;
    }

    public int getRowCount() {
        return alleEintraege.size();
    }

    public String getColumnName(int col) {
        return spaltenNamen[col];
    }

    public Object getValueAt(int row, int col) {
        Vorstellung p = alleEintraege.get(row);
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); 
        switch (col)
        {
            case 0:             
            	return p.getS_Nr();
            case 1:
            	return p.getV_Datum();
            case 2:
            	return p.getTempfilm().getName();
            case 3:          	
            	return sdf.format(p.getV_Beginn());
            case 4:
            	return sdf.format(p.getTempfilm().getDauer());
        }
        return null;
    }

    /*
     * JTable uses this method to determine the default renderer/
     * editor for each cell.  If we didn't implement this method,
     * then the last column would contain text ("true"/"false"),
     * rather than a check box.
     */
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    /*
     * Don't need to implement this method unless your table's
     * editable.
     */
    public boolean isCellEditable(int row, int col) {
        //Note that the data/cell address is constant,
        //no matter where the cell appears onscreen.
        if(col==column)
        {
            return columnEditable;
        }
        else
        {
            return false;   
        }
    }
    
    public void setEditColumn(boolean a, int col)
    {
        columnEditable=a;
        column=col;
    }
    
    public void addVorstellung(Vorstellung s)
    {
        alleEintraege.add(s);
    }
	public ArrayList<Vorstellung> getAlleEintraege() {
		return alleEintraege;
	}    
}